package com.mvp.shq.washer.ui.shareApp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.mvp.shq.washer.R;
import com.mvp.shq.washer.base.BaseActivity;
import com.mvp.shq.washer.utils.T;
import com.orhanobut.logger.Logger;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.UmengTool;
import com.umeng.socialize.bean.SHARE_MEDIA;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShareAppActivity extends BaseActivity<ShareAppPresenter, ShareAppModel> implements ShareAppConstract.View {


    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_share_num)
    TextView tvShareNum;

    @Override
    public int getLayoutId() {
        return R.layout.activity_share_app;
    }

    @Override
    public void initView() {
        StatusBarUtil.setColor(this, ContextCompat.getColor(context,R.color.white),0);
    }

    @OnClick({R.id.back, R.id.tv_rule, R.id.img_share_wx, R.id.img_share_friends, R.id.img_share_qq, R.id.img_share_scan})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.tv_rule:
                break;
            case R.id.img_share_wx:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.WEIXIN)//传入平台
                        .withText("hello bug")//分享内容
                        .setCallback(new UMShareListener() {
                            @Override
                            public void onStart(SHARE_MEDIA share_media) {
                                Logger.d("分享到微信好友开始");
                            }

                            @Override
                            public void onResult(SHARE_MEDIA share_media) {
                                Logger.d("分享到微信好友成功");
                                T.show("分享成功");
                            }

                            @Override
                            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                                Logger.d("分享到微信好友失败:"+throwable.getMessage());
                            }

                            @Override
                            public void onCancel(SHARE_MEDIA share_media) {
                                Logger.d("分享到微信好友取消");
                            }
                        })//回调监听器
                        .share();
                break;
            case R.id.img_share_friends:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)//传入平台
                        .withText("hello bug")//分享内容
                        .setCallback(new UMShareListener() {
                            @Override
                            public void onStart(SHARE_MEDIA share_media) {
                                Logger.d("分享到微信朋友圈开始");
                            }

                            @Override
                            public void onResult(SHARE_MEDIA share_media) {
                                Logger.d("分享到微信朋友圈成功");
                                T.show("分享成功");
                            }

                            @Override
                            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                                Logger.d("分享到微信朋友圈失败:"+throwable.getMessage());
                            }

                            @Override
                            public void onCancel(SHARE_MEDIA share_media) {
                                Logger.d("分享到微信朋友圈取消");
                            }
                        })//回调监听器
                        .share();
                break;
            case R.id.img_share_qq:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.QZONE)
                        .withText("hello bug")
                        .setCallback(new UMShareListener() {
                            @Override
                            public void onStart(SHARE_MEDIA share_media) {
                                Logger.d("分享到QQ空间开始");
                            }

                            @Override
                            public void onResult(SHARE_MEDIA share_media) {
                                Logger.d("分享到QQ空间成功");
                                T.show("分享成功");
                            }

                            @Override
                            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                                Logger.d("分享到QQ空间失败:"+throwable.getMessage());
                            }

                            @Override
                            public void onCancel(SHARE_MEDIA share_media) {
                                Logger.d("分享到QQ空间取消");
                            }
                        })
                        .share();
                break;
            case R.id.img_share_scan:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //QQ分享
        UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
    }
}
